package Task28;

public class SeparateThread extends Thread {
	private Result myResult = new Result();
	private Command myCommand = new Command();
	private MainWindow parentWindow;

	public SeparateThread(Command command, MainWindow myWindow) {
		myCommand = command;
		parentWindow = myWindow;
	}

	public Result getResult() {
		return myResult;
	}

	public void run() {
		WaitWindow waitWindow = new WaitWindow();
		waitWindow.show();

		Model myModel = new Model();
		Result resultModel = new Result();
		try {
			resultModel = myModel.getResult(myCommand); // !!!!!!!!!!!
		} catch (Exception e) {
			resultModel.addExceptions(e.getMessage());
		}
		myResult.addResult(resultModel);
		refreshMainWindow();
		waitWindow.hide();
	}

	private void refreshMainWindow() {
		if (parentWindow != null) {
			parentWindow.refreshLists();
		}
	}
}
